<template>
    <div>
        <!-- 顶部 滑动条 -->
        <div id="slider" class="mui-slider">
				<div id="sliderSegmentedControl" class="mui-scroll-wrapper mui-slider-indicator mui-segmented-control mui-segmented-control-inverted">
					<div class="mui-scroll">
						<a :class="['mui-control-item', item.id == 0 ? 'mui-active':'']" v-for="item in cates" :key="item.id">
							{{item.title}}
						</a>
					</div>
				</div>
        </div>
    </div>
</template>

<script>
// 1.导入 mui的js文件
import mui from '../../lib/mui/js/mui.min.js'

export default {
    data(){
        return {
			cates: [],
		}
	},
	created(){
		this.getAllCategory();
	},
    mounted(){ 
        // 当 组件中DOM结构被渲染好并放到页面中后, 会执行这个 钩子函数
        // 如果要操作元素了, 最好在 mounted 里面
        // 2.初始化滑动控件
        mui('.mui-scroll-wrapper').scroll({
        	deceleration: 0.0005 //flick 减速系数，系数越大，滚动速度越慢，滚动距离越小，默认值0.0006
        })
    },
    methods: {
		getAllCategory(){
			//获取 所有的图片分类
			this.$http.get('http://www.liulongbin.top:3005/api/getimgcategory').then(result => {
				if(result.body.status===0){
					result.body.message.unshift({ title:"全部", id:0 });
					this.cates = result.body.message;
				}
			})
		}
	},
}
</script>

<style lang="scss" scoped>
* {
    touch-action: pan-y;
}
</style>
